package com.bnz.controller;

import com.bnz.entity.Student;
import com.bnz.service.StudentService;
import com.bnz.service.impl.StudentServiceImpl;
import com.bnz.vo.StuVo;
import com.github.pagehelper.PageInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.PageContext;
import java.io.IOException;
import java.util.List;


@WebServlet("/add")
public class AddOne extends HttpServlet {
    private StudentService studentService;


    public void init() throws ServletException {

        studentService = new StudentServiceImpl();
    }

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        req.setCharacterEncoding("utf-8");
        addStudent(req ,resp);
    }
    public void addStudent(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Student student = new Student();

        student.setAge(Integer.valueOf(req.getParameter("age")));
        student.setClassname(req.getParameter("classname"));
        student.setHabby(req.getParameter("habby"));
        student.setName(req.getParameter("name"));
        student.setPhone(req.getParameter("phone"));

        int flag = studentService.addStudent(student);
        if(flag>0) {
            resp.sendRedirect("/stupage");
        }
    }
}
